home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / NotifyLib / NotifyLib.c next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  3.4 KB  |  143 lines  |  [TEXT/KAHL]

  1. /* Revision History:
  2.     
  3.     93/03/22 aih
  4.     - removed NotifyInit and its global variables
  5.     
  6.     92/03/06 AIH
  7.     - Modified to use vsprintf instead of sprintf, and changed last parameter
  8.     in functions taking a variable argument list from "short" to "int" since
  9.     the THINK C manual states that the last parameter should not be a type
  10.     that hasn't been promoted.
  11.     
  12.     91/05/08 AIH
  13.     - Adapted to accept and return error codes from alert library
  14.     
  15.     91/04/24 AIH
  16.     - Added filter parameter to custom notification
  17.     
  18.     91/04/01 AIH
  19.     - Added a set of functions for displaying an alternate default notification
  20.     alert
  21.     
  22.     91/03/07, 91/03/11, 91/04/22 AIH
  23.     - Modified for new way of calling alert library
  24.     
  25.     91/01/05 Ari Halberstadt (AIH)
  26.     - Inserted this standard header in all files */
  27.  
  28. #include <stdarg.h>
  29. #include <string.h>
  30. #include <stdio.h>
  31. #include "AlertLib.h"
  32. #include "DialogLib.h"
  33. #include "NotifyLib.h"
  34. #include "ResourceLib.h"
  35. #include "ResourceConstantsLib.h"
  36. #include "StringLib.h"
  37.  
  38. /* A general notification function. The parameters are:
  39.  
  40.     alert        The ID of the alert to display.
  41.     string    The ID of the 'STR#' resource from which to get the format string
  42.                 to pass to sprintf.
  43.     index        The index to the string in the 'STR#' resource to use as the format string.
  44.     icon        The ID of the icon to display in the upper left corner.
  45.     filter    Filter function for the alert
  46.     data        Extra application defined data for the alert
  47.     ...        After the last button, further C string (character pointer)
  48.                 parameters may be given. These parameters will be passed to
  49.                 sprintf following the format string from the 'STR#' resource.
  50.                 
  51.     These parameters allow you to use an alert template other than the one
  52.     passed to NotifyInit. */
  53. static short NotifyGeneric(short alert, short string, short index,
  54.     short icon, DlgModalFilterType filter, void *data, va_list args)
  55. {
  56.     CStr255 fmt;
  57.     CStr255 str;
  58.     int len;
  59.     
  60.     ResStr(string, index, fmt);
  61.     len = vsprintf(str, fmt, args);
  62.     check(len != EOF && len < sizeof(str));
  63.     return(AlertCustom(alert, icon, filter, data, 1, str));
  64. }
  65.  
  66. short NotifyCustom(short alert, short string, short index, short icon,
  67.     DlgModalFilterType filter, void *data, ...)
  68. {
  69.     va_list ap;
  70.     short item;
  71.     
  72.     va_start(ap, data);
  73.     item = NotifyGeneric(alert, string, index, icon, filter, data, ap);
  74.     va_end(ap);
  75.     return(item);
  76. }
  77.  
  78. void NotifyStop(int index, ...)
  79. {
  80.     va_list ap;
  81.     
  82.     va_start(ap, index);    
  83.     (void) NotifyGeneric(RLA_OK, RLS_ALERT, index,
  84.                                 stopIcon, NULL, NULL, ap);
  85.     va_end(ap);
  86. }
  87.  
  88. void NotifyNote(int index, ...)
  89. {
  90.     va_list ap;
  91.     
  92.     va_start(ap, index);
  93.     (void) NotifyGeneric(RLA_OK, RLS_ALERT, index,
  94.                                 noteIcon, NULL, NULL, ap);
  95.     va_end(ap);
  96. }
  97.  
  98. void NotifyCaution(int index, ...)
  99. {
  100.     va_list ap;
  101.     
  102.     va_start(ap, index);
  103.     (void) NotifyGeneric(RLA_OK, RLS_ALERT, index,
  104.                                 cautionIcon, NULL, NULL, ap);
  105.     va_end(ap);
  106. }
  107.  
  108. short NotifyOtherStop(int index, ...)
  109. {
  110.     va_list ap;
  111.     short item;
  112.     
  113.     va_start(ap, index);
  114.     item = NotifyGeneric(RLA_OK_CANCEL, RLS_ALERT, index,
  115.                                 stopIcon, NULL, NULL, ap);
  116.     va_end(ap);
  117.     return(item);
  118. }
  119.  
  120. short NotifyOtherNote(int index, ...)
  121. {
  122.     va_list ap;
  123.     short item;
  124.     
  125.     va_start(ap, index);
  126.     item = NotifyGeneric(RLA_OK_CANCEL, RLS_ALERT, index,
  127.                                 noteIcon, NULL, NULL, ap);
  128.     va_end(ap);
  129.     return(item);
  130. }
  131.  
  132. short NotifyOtherCaution(int index, ...)
  133. {
  134.     va_list ap;
  135.     short item;
  136.     
  137.     va_start(ap, index);
  138.     item = NotifyGeneric(RLA_OK_CANCEL, RLS_ALERT, index,
  139.                                 cautionIcon, NULL, NULL, ap);
  140.     va_end(ap);
  141.     return(item);
  142. }
  143.